﻿using System;
using System.Collections.Generic;
using System.Linq;
using BAL;
using Common;
using Entity;
using Microsoft.Reporting.WebForms;

namespace Web.WebChart
{
    public partial class ChartScoreKnow : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GenerateEvaluationReport(1);
        }

        /// 生成评估报表
        /// </summary>
        private void GenerateEvaluationReport(int pointId)
        {
            try
            {
                ReportViewer1.ProcessingMode = ProcessingMode.Local;

                //ServerReport serverReport = reportViewer.ServerReport;
                //string reportServer = ConfigurationManager.AppSettings["ReportServer"];
                //// Set the report server URL and report path
                //serverReport.ReportServerUrl = new Uri(reportServer);
                //serverReport.ReportPath = "/Hes.Report/SystemPointView";

                LocalReport localReport = ReportViewer1.LocalReport;
                List<StudentInfo> studentList = new List<StudentInfo>();
                var s1 = new StudentInfo()
                    {
                        Name = "晓丽",
                        Sex = 0,
                        ClassId = 122
                    };
                var s2 = new StudentInfo()
                {
                    Name = "张强",
                    Sex = 1,
                    ClassId = 122
                };
                var s3 = new StudentInfo()
                {
                    Name = "高飞",
                    Sex = 1,
                    ClassId = 123
                };
                studentList.AddRange(new StudentInfo[] { s1, s2, s3 });

                ReportDataSource ds = new ReportDataSource("studentInfoList", studentList);

                ReportParameter[] para = new ReportParameter[3];
                para[0] = new ReportParameter("Name", "姓名");
                para[0] = new ReportParameter("Sex", "性别");
                para[0] = new ReportParameter("Class", "班级");

                ReportViewer1.LocalReport.SetParameters(para);

            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message + "');</script>");
            }
        }

        private string[] GetClassScoreByQuest(IList<StudentScoreExtendInfo> infos, int sid, int classid, int gradeid, int areaid, IList<int> questid)
        {
            decimal myScore = 0, classScore = 0, gradeScore = 0, areaScore = 0;
            int classNum = 0, gradeNum = 0, areaNum = 0;
            foreach (StudentScoreExtendInfo info in infos)
            {
                IList<ScoreInfo> scoreInfos = ScoreHelper.GetScoreList(info.QuestItemScore);
                scoreInfos = scoreInfos.Where(t => GetArray<int>.Get(questid).Contains(t.Id)).ToList();
                decimal score = 0;
                foreach (ScoreInfo scoreInfo in scoreInfos)
                {
                    if (!PageValidate.IsEmpty(scoreInfo.Score))
                    {
                        score += decimal.Parse(scoreInfo.Score);
                    }
                }
                if (info.StudentId == sid)
                {
                    myScore = score;
                }
                if (info.ClassId == classid)
                {
                    classScore += score;
                    classNum++;
                }
                if (info.GradeId == gradeid)
                {
                    gradeScore += score;
                    gradeNum++;
                }
                if (info.AreaId == areaid)
                {
                    areaScore += score;
                    areaNum++;
                }
            }
            return new string[] { myScore.ToString(), classScore.ToString(), gradeScore.ToString(), areaScore.ToString(), classNum.ToString(), gradeNum.ToString(), areaNum.ToString() };
        }

        private IList<KnowledgeInfo> GetKnowledgeMode(int subjectid)
        {
            IList<KnowledgeInfo> infos = new List<KnowledgeInfo>();
            infos = Knowledge.GetKnowledgeInfosBySubjectId(subjectid).Where(t => t.Keyword.Length == 1).ToList();
            foreach (KnowledgeInfo info in infos)
            {
                info.ChildKnowledgeInfos = Knowledge.GetKnowledgeInfos(info.Id);
                foreach (KnowledgeInfo subInfo in info.ChildKnowledgeInfos)
                {
                    subInfo.ChildKnowledgeInfos = Knowledge.GetKnowledgeInfos(subInfo.Id);
                }
            }
            return infos;
        }

        private IList<QuestionInfo> GetQuestion(int exampaperid)
        {
            IList<QuestionInfo> infos = new List<QuestionInfo>();
            infos = Question.GetQuestions(exampaperid, "", "", "", "", "", "", "", "", "", 0, 0);
            return infos;
        }
    }
}